package com.heima.article.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.heima.article.service.AuthorService;
import com.heima.model.admin.dtos.ResponseResult;
import com.heima.model.article.pojos.ApAuthor;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(value = "app作者管理API",tags = "app作者管理API")
@RestController
@RequestMapping("/api/v1/author")
public class AuthorController {
    @Autowired
    private AuthorService authorService;
    @ApiOperation(value = "查询作者",tags = "根据ApAuthor ID查询作者信息")
    @GetMapping("/findByUserId/{id}")
    public ResponseResult<ApAuthor> findByUserId(@PathVariable("id") Integer id){
        return  ResponseResult.okResult(authorService.getOne(Wrappers.<ApAuthor>lambdaQuery()
                .eq(ApAuthor::getId,id)));
    }
    @ApiOperation(value = "保存作者",tags = "保存作者信息")
    @PostMapping("/save")
    public ResponseResult<ApAuthor> saveAuthor(@RequestBody ApAuthor apAuthor){
        authorService.save(apAuthor);
        return  ResponseResult.okResult();
    }

}
